package view
{
	import data.Globals;
	
	import flash.display.MovieClip;
	import flash.utils.getTimer;
	
	import manager.ObjectPool;
	
	import view.base.ClearView;
	
	public class AnimationView extends ClearView
	{
		public static const COUNT_DOWN:String = "count_down";
		
		private var callback:Function;
		
		private var useTime:Number;
		
		private var clip:MovieClip;
		
		public function AnimationView()
		{
			super();

			this.x = Globals.stage_width/2;
			this.y = Globals.stage_height/2;
			
			this.mouseChildren = false;
			this.mouseEnabled = false;
		}
	
		public function playClip(type:String,playEnd:Function = null):void{
		    clip = getClip(type);
			callback = playEnd;
			if(clip){
				this.addChild(clip);
	    		useTime = getTimer();
		        clip.addFrameScript(clip.totalFrames-1,remove);
				clip.play();
			}
		}
		
		private function getClip(type:String):MovieClip
		{
			var cls:Class;
			var deleteBlack:Boolean;
			switch(type){
				case COUNT_DOWN:
					cls = CountDown;
					break;
			}
			var clip:MovieClip = ObjectPool.getObj(cls) as MovieClip;
			return clip;
		}
		
		private function remove():void{
			if(clip.parent)clip.parent.removeChild(clip);
			clip.gotoAndStop(0);
			ObjectPool.putObj(clip);	
			if(callback != null){
				callback();
				callback = null;
			}
		}
	}
}